package com.yylending.las.lending.outlet;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.io.Serializable;
import java.util.List;

/**
 * 门店列表
 * Created by laixj on 2017/11/4.
 * Copyright ©2016 www.yylending.com. All Rights Reserved.
 */
public class OutletModel extends Model {
	private static final String TAG = OutletModel.class.getSimpleName();
	public static final int FUNCTION_CODE_GET_OUTLET_LIST = 121;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case FUNCTION_CODE_GET_OUTLET_LIST:
				return service.getOutletList(Global.LOGIN_TOKEN, new EmptyEntity());

		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		BaseResultEntity result = cast(entity);
		switch (result.requestCode) {
			case FUNCTION_CODE_GET_OUTLET_LIST:
				OutletInfoResult baseInfo = cast(entity);
				EventAgent.post(baseInfo);
				break;
		}
	}

	private interface Service {
		@POST("server/params/getCityStore")
		Observable<OutletInfoResult> getOutletList(@Header("token") String token, @Body EmptyEntity params);
	}

	public static class Outlet implements Serializable{
		/**
		 * 城市
		 */
		String city = "";
		/**
		 * 门店名称
		 */
		String name = "";
		/**
		 * 门店地址
		 */
		String address = "";
		/**
		 * 经度
		 */
		String longitude = "";
		/**
		 * 纬度
		 */
		String latitude = "";
		/**
		 * 联系方式
		 */
		String phone = "";
	}

	static class OutletInfoResult extends BaseResultEntity<OutletList> {
	}

	static class OutletList{
		/**
		 * 门店列表
		 */
		List<Outlet> list;
	}
}
